const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
  css: {
    loaderOptions: {
      sass: {
        implementation: require('sass') // This line must in sass option
      }
    }
  },
  // 使用 babel 编译的 npm 插件
  transpileDependencies: [
    'uni-ajax',
    'vuex-module-decorators',
    'vuex-persist',
    'uview-ui'
  ],
  productionSourceMap: false,
  configureWebpack: {
    resolve: {
      symlinks: false
    },
    plugins: [
      new CopyWebpackPlugin([
        {
          from: path.join(__dirname, 'cloudfunctions'),
          to: path.join(
            __dirname,
            'dist',
            process.env.NODE_ENV === 'production' ? 'build' : 'dev',
            process.env.UNI_PLATFORM,
            'cloudfunctions'
          )
        }
      ])
    ]
  },
  chainWebpack(config) {
    // 在打包时，让ts检查闭嘴👀
    if (process.env.NODE_ENV === 'production') {
      config.plugins.delete('fork-ts-checker')
    }
  }
}
